package com.xinxin.leetcode.problem12;

import java.util.HashMap;
import java.util.Map;
import java.util.SplittableRandom;
import java.util.Stack;

/**
 * @author ShiXinXin
 * @date 2019-08-31 22:35
 */
class Solution {
    Map<Integer, String> map = new HashMap<Integer, String>() {{
        put(0, "");
        put(1, "I");
        put(2, "II");
        put(3, "III");
        put(4, "IV");
        put(5, "V");
        put(6, "VI");
        put(7, "VII");
        put(8, "VIII");
        put(9, "IX");
        put(10, "X");
        put(20, "XX");
        put(30, "XXX");
        put(40, "XL");
        put(50, "L");
        put(60, "LX");
        put(70, "LXX");
        put(80, "LXXX");
        put(90, "XC");
        put(100, "C");
        put(200, "CC");
        put(300, "CCC");
        put(400, "CD");
        put(500, "D");
        put(600, "DC");
        put(700, "DCC");
        put(800, "DCCC");
        put(900, "CM");
        put(1000, "M");
        put(2000, "MM");
        put(3000, "MMM");
    }};

    public String intToRoman(int num) {
        Stack<Integer> stack = new Stack<>();
        int p = 1;
        while (num > 0) {
            stack.push(num % 10 * p);
            num /= 10;
            p *= 10;
        }
        StringBuilder res = new StringBuilder();
        while (!stack.empty()) {
            res.append(map.get(stack.pop()));
        }
        return String.valueOf(res);
    }

    public static void main(String[] args) {
        System.out.println(new Solution().intToRoman(10));
    }
}
